<!DOCTYPE html>
<!--
  ~ Copyright (C) 2018 guomw.Inc. All rights reserved.
  ~ 项目名称： mysite
  ~ 文件名称： edit.html
  ~ Date：18-10-15 下午4:46
  ~ Author: guomw
  -->
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>产品编辑</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link rel="shortcut icon" href="../../resource/favicon.ico" th:href="@{/resource/favicon.ico}"/>
    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>
    <link href="../../resource/css/font-awesome.min.css?v=4.4.0" rel="stylesheet"
          th:href="@{/resource/css/font-awesome.min.css?v=4.4.0}"/>
    <link href="../../resource/css/animate.min.css" rel="stylesheet" th:href="@{/resource/css/animate.min.css}"/>
    <link href="../../resource/css/style.min.css?v=4.0.0" rel="stylesheet"
          th:href="@{/resource/css/style.min.css?v=4.0.0}"/>
    <link href="../../resource/css/plugins/sweetalert/sweetalert.css?v=4.0.0" rel="stylesheet"
          th:href="@{/resource/css/plugins/sweetalert/sweetalert.css?v=4.0.0}"/>
    <link href="../../resource/css/plugins/iCheck/custom.css" rel="stylesheet"
          th:href="@{/resource/css/plugins/iCheck/custom.css}"/>
    <link href="../../resource/css/style-diy.css?v=4.0.0" rel="stylesheet"
          th:href="@{/resource/css/style-diy.css?v=4.0.0}"/>

    <!--[if lt IE 8]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->
</head>

<body class="gray-bg">
<link href="../../resource/css/plugins/summernote/summernote.css" rel="stylesheet">
<link href="../../resource/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
<link href="../../resource/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet"/>
<div class="wrapper wrapper-content  animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <span style="font-size:20px;font-weight:bold;">直播商品编辑</span>
            <div class="ibox-tools">
                <button type="button" class="btn btn-success" onclick="window.history.go(-1);">返回列表</button>
            </div>
        </div>
        <div class="ibox-content" th:object="${productInfo}">
            <fieldset>
                <form method="post" action="/product/liveSave" id="editForm" class="form-horizontal">
                    <fieldset>
                        <input type="hidden" name="productId" th:value="${productInfo.productId}"/>

                        <!--<input type="hidden" name="roomId" th:value="${productInfo.roomId}"/>-->
                        <input type="hidden" name="merchantId" value="1"/><!--todo 写死的商家id-->
                        <div class="form-group form-inline" style="display: none;">
                            <label class="col-sm-2 control-label"><font color="red">*</font> 类型</label>
                            <div class="col-sm-4">
                                <select class="form-control" name="sourceType">
                                    <option value="1">直播间商品</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group form-inline">
                            <label class="col-sm-2 control-label"><font color="red">*</font> 销售类型</label>
                            <div class="col-sm-4">
                                <select class="form-control" name="saleTypeCode">
                                    <option th:selected="${productInfo.saleType.code==0}" value="0">普通</option>
                                    <option th:selected="${productInfo.saleType.code==1}" value="1">拍卖</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><font color="red">*</font>商品名称</label>
                            <div class="col-sm-4">
                                <!--/*@thymesVar id="templateInfo" type="com.treasure.mall.biz.entity.product.ProductPO"*/-->
                                <input class="form-control " name="productName" id="productName" type="text" value=""
                                       th:value="${productInfo.productName}">
                            </div>
                        </div>
                        <div class="form-group form-inline">
                            <label class="col-sm-2 control-label">库存</label>
                            <div class="col-sm-4">
                                <input name="store" id="store" type="text" class="form-control input-s-sm only-num"
                                       placeholder="数量" th:value="${productInfo.store}">
                            </div>
                        </div>
                        <div class="form-group" style="display: none">
                            <label class="col-sm-2 control-label"><font color="red">*</font>售价</label>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <span class="input-group-addon">¥</span>
                                    <input name="price" id="price" type="text"
                                           class="form-control input-s-sm only-float" placeholder="售价"
                                           th:value="${productInfo.price}">
                                </div>
                            </div>
                        </div>
                        <div class="form-group form-inline">
                            <label class="col-sm-2 control-label"><font color="red"></font> 服务标签</label>
                            <div class="col-sm-4">
                                <div class="checkbox checkbox-primary" th:each="tag:${serviceTags}">
                                    <input type="checkbox" id="tag_1" th:checked="${tag.code==0}"
                                           th:disabled="${tag.code==0}" th:id="|tag_${tag.code}|" th:value="${tag.code}"
                                           name="chkServiceTag" value="1">
                                    <label for="tag_1" th:for="|tag_${tag.code}|"><font
                                            th:text="${tag.desc}">全国包邮</font></label>
                                </div>

                                <input type="hidden" name="serviceTags" id="serviceTags"
                                       th:value="${productInfo.serviceTags}"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">商品主图</label>
                            <div class="col-sm-4">
                                <input type="hidden" name="picList" id="picList"/>
                                <input type="file" style="display: none" id="uploadfile" name="uploadfile"
                                       readonly="readonly"
                                       class="form-control">
                                <a title="选择图片">
                                    <img class="imgpreview" src="../../resource/img/bg.png"
                                         onerror="this.src='/resource/img/bg.png'"
                                         style="margin-top: 10px; width:150px;height:150px;"
                                    />
                                </a>
                                <div style="color: grey;">建议尺寸：400*400</div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">尺寸</label>
                            <div class="col-sm-4">
                                <input class="form-control " name="propSize" id="propSize" type="text" value="尺寸"
                                       th:value="${productInfo.propSize}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">专属用户idddd</label>
                            <div class="col-sm-4">
                                <input class="form-control " type="text" name="exclusiveUserId"
                                       th:value="${productInfo.exclusiveUserId}"/>

                                </button>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">房间id</label>
                            <div class="col-sm-4">
                                <input class="form-control " type="text" name="roomId" th:value="1"/>
                            </div>
                        </div>
                        <div class="col-sm-offset-5">
                            <button id="btnSubmitData" type="submit" class="btn btn-primary">保存</button>
                        </div>
                        <input type="hidden" th:value="${@resourceService.getResourceDomain()}" id="hidResourceDomain"/>
                    </fieldset>
                </form>
            </fieldset>
        </div>
    </div>

</div>

<script src="../../resource/js/jquery.min.js?v=2.1.4" th:src="@{/resource/js/jquery.min.js?v=2.1.4}"></script>
<script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js?v=3.3.5}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?666666"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?666666}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316?1234567"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316(123)}"></script>
<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>


<script src="https://cdn.bootcss.com/jquery.form/4.2.2/jquery.form.min.js"></script>
<script src="/resource/lib/jquery-chain-select/jquery.chainSelect.js?xxxxx"></script>
<script src="/resource/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="/resource/lib/jquery-validation/dist/messages_cn.js"></script>

<script src="../../resource/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
<script src="/resource/js/plugins/summernote/summernote.min.js"></script>
<script src="/resource/js/plugins/summernote/summernote-zh-CN.js"></script>
</body>
<script type="text/javascript">
    $(function () {
        pageHandler.init();
    });

    var pageHandler = {
        init: function () {
            this.regValidator();
            $("#editForm").submit(function () {
                pageHandler.ajaxSubmit();
                return false;
            });

            $('form').each(function () {
                if ($(this).data('validator'))
                    $(this).data('validator').settings.ignore = ".note-editor *";
            });
            //上传
            $('.imgpreview').click(function () {
                $("#uploadfile").click();
            });
            $('body').delegate("#uploadfile", 'change', function () {
                hotUtil.loading.show();
                hotUtil.uploadImg($("#uploadfile")[0].files, "product", function (url, path) {
                    hotUtil.loading.close();
                    $(".imgpreview").attr("src", url);
                    $("#video").val(path);
                });
            });
            this._afterLoaded();
        },
        regValidator: function () {
            $("#editForm").validate({
                ignore: ".note-editor *",
                rules: {
                    productName: {
                        required: true
                    },
                    price: {
                        required: true
                    }
                },
                messages: {},
                errorClass: 'help-block help-block-error',
                focusInvalid: false,
                highlight: function (element) {
                },
                success: function (label, element) {
                    $(element).closest('.form-group').removeClass('has-error');
                    $(element).attr("title", "").tooltip("hide");
                },
                errorPlacement: function (error, element) {
                    if ($(element).next("div").hasClass("tooltip")) {
                        $(element).attr("data-original-title", $(error).text()).tooltip("show");
                    } else {
                        $(element).attr("title", $(error).text()).tooltip("show");
                    }
                },
                submitHandler: function (form) {
                }
            });
        },
        setButtonDisabled: function (flag) {
            if (flag) {
                $('#btnSubmitData').attr('disabled', 'disabled').html('保存中');
            } else {
                $('#btnSubmitData').removeAttr('disabled').html('保存');
            }
        },
        _afterLoaded: function () {
            var serviceTagsStr = $('#serviceTags').val();
            $('input[name="chkServiceTag"]').each(function () {
                if (serviceTagsStr.indexOf(',' + $(this).val() + ',') != -1) {
                    $(this).attr('checked', 'checked');
                }
            });
        },
        _preSubmit: function () {
            var serviceTags = [];
            $('input[name="chkServiceTag"]:checked').each(function () {
                serviceTags.push($(this).val());
            });
            $('#serviceTags').val(',' + serviceTags.join(',') + ',');
        },
        ajaxSubmit: function () {
            var self = this;
            self._preSubmit();
            $("#editForm").ajaxSubmit({
                resetForm: false,
                beforeSubmit: function (formData, jqForm, options) {
                    if (!$("#editForm").valid()) return false;
                    layer.load();
                    self.setButtonDisabled(true);
                },
                type: "post",
                dataType: "json",
                success: function (rep) {
                    if (rep.success) {
                        layer.close();
                        layer.msg("保存成功");
                        setTimeout(function () {
                            window.location.href = '/product/liveList';
                        }, 888);
                    } else {
                        layer.alert(rep.msg, {icon: 5});
                        self.setButtonDisabled(false);
                    }
                },
                error: function () {
                    layer.alert("网络错误，请稍候再试。", {icon: 5});
                    self.setButtonDisabled(false);
                }
            });
        }
    };
</script>
</html>